package com.bmf.module.examination.controller;

import com.bmf.core.result.PageResponse;
import com.bmf.module.examination.service.TestPaperService;
import com.bmf.module.examination.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.bmf.core.result.R;
import java.util.List;


/**
 * (TestPaper)表控制层
 *
 * @author makejava
 * @since 2022-12-02 14:39:07
 */
@RestController
@RequestMapping("testPaper")
@Api(tags = {"试卷接口"})
public class TestPaperController{
    /**
     * 服务对象
     */
    @Autowired
    private TestPaperService testPaperService;

    /**
     * 生成试题
     *
     * @return 所有数据
     */
    @GetMapping("/getTestPaper")
    @ApiOperation(value = "生成试题")
    public R<ExaminationResultsCreateVo> getTestPaper(Integer id,String studentName) {
        return R.success(testPaperService.getTestPaper(id,studentName));
    }

    /**
     * 保存答题
     *
     * @param examinationResultsCreateVo 实体对象
     * @return 修改结果
     */
    @PostMapping
    @ApiOperation(value = "保存答题")
    public R<Void> saveTest(@RequestBody ExaminationResultsCreateVo examinationResultsCreateVo) {
        testPaperService.saveTest(examinationResultsCreateVo);
        return R.ok();
    }

    /**
     * 查询保存答题
     */
    @GetMapping("/querySubmitTest/{testinfoId}")
    @ApiOperation(value = "查询提交试题")
    public R<ExaminationResultsCreateVo> querySaveTest(@PathVariable("testinfoId") Integer testinfoId) {
        return R.success(testPaperService.querySaveTest(testinfoId));
    }

    /**
     * 提交答题
     */
    @PostMapping("/submitTest")
    @ApiOperation(value = "提交答题")
    public R<Void> submitTest(@RequestBody ExaminationResultsCreateVo examinationResultsCreateVo) {
        testPaperService.submitTest(examinationResultsCreateVo);
        return R.ok();
    }

    /**
     * 通过试卷id查询考试信息
     * @param id
     * @return
     */
    @GetMapping("/selectTestList/{id}")
    @ApiOperation(value = "通过试卷id查询考试信息")
    public R<List<TestPaperResultVo>> selectTestList(@PathVariable("id") Integer id) {
        return R.success(testPaperService.selectTestList(id));
    }

    /**
     * 通过考试试卷id查询试卷信息
     * @param id
     * @return
     */
    @GetMapping("/selectTestPaperInfo/{id}")
    @ApiOperation(value = "通过考试试卷id查询试卷信息")
    public R<List<BigQuestionTestPaperResultVo>> selectTestPaperInfo(@PathVariable("id") Integer id) {
        return R.success(testPaperService.selectTestPaperInfo(id));
    }

    /**
     * 修改试卷
     */
    @PostMapping("/updateTest")
    @ApiOperation(value = "修改试卷")
    public R<Void> updateTest(@RequestBody TestPaperUpdateVo testPaperUpdateVo) {
        testPaperService.updateTest(testPaperUpdateVo);
        return R.ok();
    }

    /**
     * 成绩统计
     */
    @GetMapping("/achievementStatistics/{testinId}")
    @ApiOperation(value = "成绩统计")
    public R<List<AchievementResultVo>> achievementStatistics(@PathVariable("testinId") Integer testinId) {
        return R.success(testPaperService.achievementStatistics(testinId));
    }

    /**
     * 统计查询
     */
    @PostMapping("/statisticalQuery")
    @ApiOperation(value = "统计查询")
    public R<PageResponse<StatisticalResultVo>> statisticalQuery(@RequestBody StatisticalQueryVo statisticalQueryVo) {
        return R.success(testPaperService.statisticalQuery(statisticalQueryVo));
    }

    /**
     * 导出
     */
    @GetMapping("/leadingOut/{id}")
    @ApiOperation(value = "导出")
    public R<Void> leadingOut(@PathVariable("id") Integer id) {
        testPaperService.leadingOut(id);
        return R.ok();
    }

    /**
     * 判断有无次数
     */
    @GetMapping("/judgeHasTestCount/{testid}/{studentName}")
    @ApiOperation(value = "判断有无次数")
    public R<Void> judgeHasTestCount(@PathVariable("testid") Integer testid,@PathVariable("studentName") String studentName){
        testPaperService.judgeHasTestCount(testid,studentName);
        return R.ok();
    }
    /**
     * 判断有无次数
     */
    @GetMapping("/judgeHasTestCountByStudentid/{testid}")
    @ApiOperation(value = "判断有无次数")
    public R<Void> judgeHasTestCountByStudentid(@PathVariable("testid") Integer testid){
        testPaperService.judgeHasTestCountByStudentid(testid);
        return R.ok();
    }




}

